<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    public function index()
    {
        return view('admin.index.login');
    }


    public function login(Request $request)
    {
        $params = $this->validate($request, [
            'username' => 'required',
            'password' => 'required',
        ]);
        $bool = auth()->attempt($params);
        if ($bool) {
            return redirect(route('admin.index'));
        }
        return redirect(route('admin.login'))->withErrors('用户名或者密码错误');
    }

    public function logout(){
        auth()->logout();
        return redirect(route('admin.login'))->withErrors('请重新登录');
    }
}
